<?php
	include("../../include/dbconnect.php");
	
	$table="chungloai";
	$table_related=array($table,"hang");
	$field_related="idchungloai";
	session_start();
	header('Content-type: application/json; charset=utf-8');
	if(!isset($_SESSION["un"])) $_SESSION["un"]="";
	if($_SESSION["un"]=="")
		echo "{\"status\":0,\"msg\":\"Chưa đăng nhập !\"}";
	else if($_POST["id"]=="0")
		echo "{\"status\":0,\"msg\":\"Không phải chủng loại !\"}";
	else
	{
		if($_POST["id"]=="0") die("{\"status\":0}");
		$found=0;
		foreach($table_related as $t)
		{
			$rs=mysql_query("select * from $t where $field_related=".$_POST["id"],$conn);
			if(mysql_num_rows($rs)>0) $found++;
			mysql_free_result($rs);
		}
		if($found>0) die("{\"status\":0}");
		else
		{
			mysql_query("delete from $table where id=".$_POST["id"],$conn) or die("{\"status\":0}");
			echo "{\"status\":1}";
		}
	}
	include("../../include/dbclose.php");
?>
